package com.jinlia.show.modules.wxapp.controller;

import com.jinlia.show.modules.wxapp.websocket.WebSocketService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("web/socket")
public class WebSocketController {

    @Autowired
    WebSocketService webSocketService;

    @GetMapping("/user/{userId}")
    public Boolean sentTo(@PathVariable(name = "userId") String userId, @Param("text") String text) {
        return webSocketService.sendMsg(userId, text);
    }

    @GetMapping("/broadcast")
    public Boolean sentTo(@RequestParam("text") String text) {
        webSocketService.broadcastMsg(text);
        return Boolean.TRUE;
    }
}
